package cn.hyy.hrm.controller;


import cn.hyy.basic.util.AjaxResult;
import cn.hyy.hrm.config.SMSConst;
import cn.hyy.hrm.util.SMSUtil;
import com.aliyuncs.exceptions.ClientException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/send")
public class SMSSendController {

    /**
     * 发送注册短信验证码
     * @param phoneNum 手机号码
     * @param code 验证码
     * @return
     */
    @GetMapping("/regSMSCode")
    public AjaxResult sendRegSMSCode(@RequestParam("phoneNum") String phoneNum, @RequestParam("code") String code){

        String templateParam = "{\"code\":\""+code+"\"}";
        try {
            SMSUtil.INSTANCE.sendSMS(phoneNum, SMSConst.SIGNNAME_REG_SMS_CODE,SMSConst.TEMPLATE_REG_SMS_CODE,templateParam);
            return AjaxResult.me().setSuccess(true).setMessage("发送成功!");
        } catch (ClientException e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("发送失败!");
        }
    }
}
